package ru.dc.object.commands;

/**
 * <h3>Syntax</h3>
 * <pre>
 * $Get &lt;file>$&lt;offset>|
 * </pre>
 * <h3>Description</h3>
 * <p>This command is used to request a file from the uploading client.</p>
 * <ul>
 * <li>&lt;file> is the full file name and the path to it, as per the source's $SR or FileList.</li>
 * <li>&lt;offset> is the starting point of the download (counted from 1, not from 0) </li>
 * </ul>
 * <p>
 * The $Error with "File Not Found" is sent when the file is not available. NMDC disconnects the user
 * if no directory is provided. (i.e. $Error on "$Get nonexistent_directory\nonexistent_file$1|" and disconnect
 * on "$Get nonexistent_file$1|")
 * </p>
 * <p>
 * When the file is available, the source must respond with $FileLength.
 * </p>
 * <p/>
 * <p>
 * The FileList is retrieved with "$Get MyList.DcLst$1|"
 * </p>
 * <a href="http://www.teamfair.info/wiki/index.php?title=$Get">http://www.teamfair.info/wiki/index.php?title=$Get</a>
 */
public class Get extends Command {

    private String filename;
    private long offset = 1;

    @Override
    public String generateCommand() {
        return getActualCommandName()+" "+getFilename()+"$"+getOffset();
    }

    @Override
    public String getActualCommandName() {
        return "$Get";
    }

    @Override
    public void parseCommand() {
        String data = getCommand().substring(getActualCommandName().length()+1);
        String[] tokens = data.split("\\$");
        setFilename(tokens[0]);
        setOffset(new Integer(tokens[1]));
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public long getOffset() {
        return offset;
    }

    public void setOffset(long offset) {
        this.offset = offset;
    }
}
